package com.npf.imgserver.thread;

import com.npf.imgserver.entity.Customer;
import com.npf.imgserver.entity.ImgInfo;
import com.npf.imgserver.service.api.ImgInfoService;
import com.npf.imgserver.utils.SpringBeanUtil;
import lombok.Data;

import java.util.concurrent.Callable;

/**
 * Created with IDEA
 * 异步线程 保存图片信息
 * author: NiPengFei
 * Date:18/9/23
 * Time:下午9:54
 */
@Data
public class SaveImgThreadAsyc implements Callable<Integer> {

    //@Autowired
    //private ImgInfoService imgInfoService;//spring容器出于线程安全考虑，不能注入bean至线程类

    /**
     * 图片操作 service类 手动注入
     */
    private ImgInfoService imgInfoService;

    /**
     * 接入商信息
     */
    private Customer customer;

    @Override
    public Integer call() throws Exception {
        //手动注入service
        this.imgInfoService = (ImgInfoService) SpringBeanUtil.getBeanByName("imgInfoService");
        ImgInfo imgInfo = new ImgInfo();
        imgInfo.setAppKey(this.customer.getAppKey());
        imgInfo.setCustomerId(this.customer.getCustomerId());
        imgInfo.setCustomerName(this.customer.getCustomerName());
        imgInfo.setImgUrl(this.customer.getImgUrl());
        return imgInfoService.saveImgInfo(imgInfo);
    }
}
